<?php

define('HTML_EOL', '<br>');

function numberToArray($month_days = 31, $first_day = 1, $define_value = null)
{
    $result = array();
    # $month_days++;
    for ($i = $first_day; $i < $month_days; $i++) {
        if ($define_value) {
            $result[] = $define_value;
        } else {
            $result[] = $i;
        }
    }
    return $result;

}

function viewArrayToHTML($arr, $sep = HTML_EOL, $from = null)
{
    $arr_first_key = key($arr);
    if (!isset($arr[$arr_first_key])) {
        # print_r(debug_backtrace());
        print_r(get_defined_vars());exit;
    }

    $first_item_type = gettype($arr[$arr_first_key]);
    if ('array' != $first_item_type) {
        $result = implode($sep, $arr);
        return $result;
    }

    $result = array();
    foreach ($arr as $key => $value) {
        $result[] = viewArrayToHTML($value);
    }
    $result = implode($sep, $result);
    # echo $result;exit;
    # print_r($result);exit;
    return $result;
}

function numberToArrayMerge($array = array())
{
    $arr = array();
    foreach ($array as $key => $value) {
        list($days, $day_start, $year_no) = $value;
        $arr = array_merge($arr, numberToArray($days, $day_start, $year_no));
    }
    return $arr;
}

$ar = array();
$ar[] = array(5, 1, 1);
$ar[] = array(5, 1, 2);
$ar[] = array(5, 1, 3);
$ar[] = array(6, 1, 4);
$arr = numberToArrayMerge($ar);
echo $html = viewArrayToHTML($arr);
